# -*- coding: utf-8 -*-
"""
Created on Tue Sep 28 18:56:19 2021

@author: think
"""

templates = [57, 49, 41, 33, 25, 17, 9 ,
             1, 58, 50, 42, 34, 26, 18, 
             10, 2, 59, 51, 43, 35, 27, 
             19, 11, 3, 60, 52, 44, 36, 
             63, 55, 47, 39, 31, 23, 15, 
             7, 62, 54, 46, 38, 30, 22, 
             14, 6, 61, 53, 45, 37, 29, 
             21, 13, 5, 28, 20, 12, 4]

steps = [1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1]

compress = [14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, 
            23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, 
            41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 
            44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32]


def pc_1(origin_key):
    temp = []
    for i in range(len(templates)):
        temp.append(origin_key[templates[i] - 1])
    
    return temp


def moveKeys(key, n):
    L = key[:28]
    R = key[28:]
    
    for i in range(n):
        L += [L.pop(0)]
        R += [R.pop(0)]
        
    return L + R


def pc_2(key):
    temp = []
    for i in range(len(compress)):
        temp.append(key[compress[i] - 1])
    
    return temp
    

def createKeys(origin_key):
    keys = []
    
    key = pc_1(origin_key)
    
    for i in range(16):
        key = moveKeys(key, steps[i])
        keys.append(pc_2(key))
        
    return keys